package mpYoga

import (
	"duoke/model"
	"duoke/service/common"
	"duoke/tables"
	"duoke/utils/response"
	"duoke/utils/valid"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

var Notice = new(noticeCtl)

type noticeCtl struct{}

func (ctl *noticeCtl) List(c *gin.Context) {
	var req model.ReqListV2
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	var list []tables.YogaNotice
	where := fmt.Sprintf("venue_id=%d", req.FromId)
	count, err := common.Tales.Infos(c, &req, where, "*").Table("yoga_notice").
		FindAndCount(&list)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", gin.H{"total": count, "list": list})
}
func (ctl *noticeCtl) Info(c *gin.Context) {
	var req model.ReqId
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	where := fmt.Sprintf("id=%d", req.Id)
	var info tables.YogaNotice
	get, err := common.Tales.Info(where, "*").Get(&info)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	if !get {
		response.Error(c, "数据不存在", nil)
		return
	}
	response.Success(c, "success", info)
}
